package com.ruibang.glass.equipment.controller;


import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.TechnicalDocumentReq;
import com.ruibang.glass.equipment.entity.device.TechnicalDocumentManagement;
import com.ruibang.glass.equipment.service.TechnicalDocumentManagementService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 技术文档管理
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/technical/document")
@Api(value = "技术文档管理")
public class TechnicalDocumentManagementController {
    @Autowired
    private TechnicalDocumentManagementService technicalDocumentManagementService;

    @PostMapping("list")
    @ApiOperation(value = "获取技术文档管理", response = ResultBody.class)
    public ResultBody getPageList(@RequestBody TechnicalDocumentReq boilerInfo) {
        return ResultBody.success(technicalDocumentManagementService.queryPage(boilerInfo));
    }

    @PostMapping("add")
    @ApiOperation(value = "新增技术文档", response = ResultBody.class)
    public ResultBody add(@RequestBody TechnicalDocumentManagement technicalDocumentManagement) {
        return technicalDocumentManagementService.add(technicalDocumentManagement);
    }

    @GetMapping("/deleteById/{id}")
    @ApiOperation(value = "根据ID删除", response = ResultBody.class)
    public ResultBody deleteById(@PathVariable("id") String id) {
        technicalDocumentManagementService.lambdaUpdate().eq(TechnicalDocumentManagement::getId,id).set(TechnicalDocumentManagement::getIsDelete, Constants.ONE_STR).update();
        return ResultBody.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改", response = ResultBody.class)
    public ResultBody update(@RequestBody TechnicalDocumentManagement technicalDocumentManagement) {
        technicalDocumentManagementService.lambdaUpdate().set(TechnicalDocumentManagement::getUpdateTime, LocalDateTime.now()).eq(TechnicalDocumentManagement::getId, technicalDocumentManagement.getId()).update();
        return ResultBody.success();
    }

    @GetMapping("getDeviceList")
    @ApiOperation(value = "获取下拉关联设备", response = ResultBody.class)
    public ResultBody getDeviceList() {
        return technicalDocumentManagementService.getDeviceList();
    }
}
